// https://acm.hdu.edu.cn/showproblem.php?pid=2602

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int max_weight;
int dp[1010];
int weights[1010], values[1010];

int main() {
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &max_weight);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &values[i]);
        }
        for (int i = 1; i <= n; i++) {
            scanf("%d", &weights[i]);
        }

        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; i++) {
            for (int j=max_weight; j>=weights[i]; j--) {
                dp[j] = max(dp[j], dp[j-weights[i]] + values[i]);
            }
        }
        printf("%d\n", dp[max_weight]);
    }
    return 0;
}